// export const baseUrl = `http://47.111.67.42:80/dev-api`
export const baseUrl = `https://zglrx.com/dev-api`

export default ({ url, method, header, data, loading, ...options }) => {
	return new Promise((resolve, reject) => {
		let _url = `${baseUrl}${url}`
		uni.request({
		    url: _url,
		    data,
				method,
		    header: {
					'Authorization': `Bearer ${uni.getStorageSync('token')}`,
					// accessToken: getUserInfo().accessToken,
					// 'bankType': "0",
					// 'client': 2,
					// 'Client-Id': deviceNo,
		        ...header
		    },
			...options,
		    success: (res) => {
				if(res.statusCode !== 200) {
					uni.showToast({
						title: res.data.msg || '网络错误，请重试',
						icon: 'none',
						duration: 2000
					})
					reject(res.data)
				} else {
					if(res.data.code == 200 || res.data.code == '200') {
						resolve(res.data)
					} else if(res.data.code == 11007 || res.data.code == 11002) {
						console.log("接口登录失效");
						reject(res.data)
					}else {
						uni.showToast({
							title: res.data.msg || '网络错误，请重试',
							icon: 'none',
							duration: 2000
						})
						reject(res.data)
					}
				}
		    },
			fail: (err) => {
				uni.showToast({
					title: err.errMsg || '',
					icon: 'none',
					duration: 2000
				})
				reject(err)
			}
		})
	})
}